package com.music.order.service.impl;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

import com.music.order.client.MusicFeign;
import com.music.order.vo.OrderMusicVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.music.order.mapper.OrderMusicMapper;
import com.music.order.domain.OrderMusic;
import com.music.order.service.OrderMusicService;

import javax.annotation.Resource;

/**
 * 订单音乐列表Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-10-22
 */
@Service
public class OrderMusicServiceImpl implements OrderMusicService
{
    @Autowired
    private OrderMusicMapper orderMusicMapper;

    @Resource
    private MusicFeign musicFeign;
    /**
     * 查询订单音乐列表
     * 
     * @param orderId 订单音乐列表主键
     * @return 订单音乐列表
     */
    @Override
    public OrderMusic selectOrderMusicByOrderId(Long orderId)
    {
        return orderMusicMapper.selectOrderMusicByOrderId(orderId);
    }

    /**
     * 查询订单音乐列表列表
     * 
     * @param orderMusic 订单音乐列表
     * @return 订单音乐列表
     */
    @Override
    public List<OrderMusic> selectOrderMusicList(OrderMusic orderMusic)
    {
        return orderMusicMapper.selectOrderMusicList(orderMusic);
    }

    /**
     * 新增订单音乐列表
     * 
     * @param orderMusic 订单音乐列表
     * @return 结果
     */
    @Override
    public int insertOrderMusic(OrderMusic orderMusic)
    {
        return orderMusicMapper.insertOrderMusic(orderMusic);
    }

    /**
     * 修改订单音乐列表
     * 
     * @param orderMusic 订单音乐列表
     * @return 结果
     */
    @Override
    public int updateOrderMusic(OrderMusic orderMusic)
    {
        return orderMusicMapper.updateOrderMusic(orderMusic);
    }

    /**
     * 批量删除订单音乐列表
     * 
     * @param orderIds 需要删除的订单音乐列表主键
     * @return 结果
     */
    @Override
    public int deleteOrderMusicByOrderIds(Long[] orderIds)
    {
        return orderMusicMapper.deleteOrderMusicByOrderIds(orderIds);
    }

    /**
     * 删除订单音乐列表信息
     * 
     * @param orderId 订单音乐列表主键
     * @return 结果
     */
    @Override
    public int deleteOrderMusicByOrderId(Long orderId)
    {
        return orderMusicMapper.deleteOrderMusicByOrderId(orderId);
    }

    @Override
    public List<OrderMusicVo> selectOrderVoMusicList(OrderMusic orderMusic) {
        List<OrderMusic> orderMusicList = orderMusicMapper.selectOrderMusicList(orderMusic);
        List<OrderMusicVo> orderMusicVoList = new ArrayList<OrderMusicVo>();
        for (OrderMusic om : orderMusicList) {
            OrderMusicVo omVo = new OrderMusicVo();
            omVo.setOrderId(om.getOrderId());
            omVo.setMusicId(om.getMusicId());
            omVo.setActivateUserId(om.getActivateUserId());

            String musicName = musicFeign.getMusicName(om.getMusicId());
            String SingerName = musicFeign.getSingerName(om.getMusicId());
            omVo.setMusicName(musicName);
            omVo.setSingerName(SingerName);
            orderMusicVoList.add(omVo);
        }
        orderMusicVoList.sort(Comparator.comparing(OrderMusic::getMusicId));
        return orderMusicVoList;
    }
}
